﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
  public partial class WorkflowsControl : AdminUserControl
  {
    public WorkflowsControl()
    {
      InitializeComponent();

      UIActionList actions = new UIActionList();
      actions.Add("Refresh", "Refreshes the list of workflows",
        new ActionExecuteDelegate(RefreshWorkflows));
      //actions.Add("Publish workflow...", "Publish a workflow assembly to the database",
      //  new ActionExecuteDelegate(PublishWorkflow));
      uiActionsControl.Actions = actions;
    }

    private WorkflowCollection workflows;
    public void LoadWorkflows(WorkflowCollection workflows)
    {
      this.workflows = workflows;
      workflowsGrid.DataSource = null;
      workflowsGrid.DataSource = workflows;
      workflowsGrid.ClearColumns();
      workflowsGrid.AddColumn("Name");
      workflowsGrid.AddColumn("Guid");
      workflowsGrid.AutosizeColumns();
    }

    private string RefreshWorkflows()
    {
      workflows.Refresh();
      LoadWorkflows(workflows);
      OnRefreshRequired();
      return null;
    }

    // requires .NET 3
    //private string PublishWorkflow()
    //{
    //  using (OpenFileDialog dialog = new OpenFileDialog())
    //  {
    //    dialog.Filter = "Workflow assemblies (*.dll)|*.dll";
    //    if (dialog.ShowDialog() == DialogResult.OK)
    //    {
    //      workflows.Server.PublishWorkflow(dialog.FileName);
    //      return "Workflow published";
    //    }
    //    return null;
    //  }
    //}
  }
}
